import axios from 'axios'
// 进度条
import nprogress from 'nprogress'
import "nprogress/nprogress.css"

// 创建axios实例
const requests = axios.create({
    baseURL: '/api',
    timeout: 5000
})

// 请求拦截器
requests.interceptors.request.use((config)=>{
    nprogress.start()
    return config
})

// 响应拦截器
requests.interceptors.response.use((res)=>{
    nprogress.done()
    return res.data
}, (error)=>{
    // 响应失败的回调函数 终止promise链
    return Promise.reject(new Error('fail'))
})

export default requests